|
This page last changed on Jul 25, 2008 by rich.
See http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html and
http://service.baynote.net/tomcat-docs/printer/jndi-datasource-examples-howto.html
1) Copy the following into CATALINA_HOME/common/lib:
a) jTDS JDBC Driver (for MS SQL Server)
b) Apache commons-pool
c) Apache commons-dbcp
d) Apache commons-logging
e) Apache commons-collection
*** these files will be named like: commons-dbcp-1.2.1.jar
and should reside in the common/lib folder, not a subfolder (winzip might extract
them to a sub-folder of the name commons-dbcp-1.2.1)
2) Configure the JNDI DataSource in Tomcat by adding a declaration for your
resource to $CATALINA_HOME/conf/server.xml. Add this in between the </Context>
tag of the examples context and the </Host> tag closing the localhost definition.
<Context path="/rovctd" docBase="rovctd" reloadable="true" crossContext="true">
<Resource
driverClassName="net.sourceforge.jtds.jdbc.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="10"
maxIdle="5"
maxWait="5000"
name="jdbc/ROVCTD"
password="password"
type="javax.sql.DataSource"
url="jdbc:jtds:sqlserver://mando.shore.mbari.org:1433/Expd"
username="expddba"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
</Context>
3) Add the following snippet to your applications WEB-INF/web.xml file. You
should ensure that you respect the element ordering defined by the DTD when you
create you applications web.xml file.
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>jdbc/ROVCTD</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4) make sure jTds driver file is in
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib
(also might need it in C:\Program Files\Apache Software Foundation\Tomcat 5.5\shared\lib
but when I was test deploying to anvil it was needed in common)
5) Fetching the connection will be done by:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/ROVCTD");
Connection conn = ds.getConnection();
LOOK AT THESE EXAMPLES FOR conf\server.xml and web.xml
;
|